home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / os2 / cenvi2.arj / BOUNCY.CMD < prev    next >
OS/2 REXX Batch file  |  1993-10-29  |  6KB  |  167 lines

  1. EXTPROC CEnvi
  2. /**************************************************************
  3.  *** Bouncy.cmd - Start a bouncy OS/2 Command Window. This  ***
  4.  ***              demonstrates moving windows, embedding    ***
  5.  ***              multiple Cmm executables within one file, ***
  6.  ***              passing keystrokes, clipboard use, and    ***
  7.  ***              silliness.                                ***
  8.  **************************************************************/
  9.  
  10. #include <KeyPush.lib>
  11. #include <ClipBrd.lib>
  12. #include <PMdll.lib>
  13.  
  14. BouncyWindowName = "Bouncy OS/2 Window";
  15.  
  16. main(argc,argv)
  17. {
  18.    // Start a different command session
  19.    system("start \"%s\" /F /WIN /K mode 80,25",BouncyWindowName);
  20.  
  21.    // Send Keystrokes to that session for smallest font
  22.    KeyStroke(VK_ALT);
  23.    KeyStroke('f');
  24.    KeyStroke(VK_HOME);
  25.    KeyStroke(VK_ENTER);
  26.  
  27.    // Tell window to clear screen by sending that command from the clipboard
  28.    PutClipboardData("cls\r",4,CF_TEXT);
  29.    KeyStroke(VK_ALT);
  30.    KeyStroke('p');
  31.  
  32.    // Start the resident portion of this program, telling it the
  33.    // Window handle to control
  34.    system("start \"Bouncy Boss\" /N /B /WIN /MIN CEnvi #include '%s,,,/*RESIDENT*/' Forever(%d)",
  35.           argv[0],GetWindowHandle(BouncyWindowName));
  36. }
  37.  
  38. GetWindowHandle(WindowName)
  39. {
  40.    // build list of all window titles
  41.    SwitchList = WinQuerySwitchList(PMInfo().hab);
  42.    for ( i = GetArraySpan(SwitchList); 0 <= i; i-- ) {
  43.       if ( 0 == WinQuerySwitchEntry(SwitchList[i],SwEntry) ) {
  44.          if ( !strcmp(WindowName,SwEntry.title) )
  45.             return(SwEntry.hwnd);
  46.       }
  47.    }
  48.    // if made it here then window not found, so exit
  49.    exit(1);
  50. }
  51.  
  52.  
  53. /*Resident*/
  54. /***********************************************************
  55.  *** Code below this section becomes resident and hidden ***
  56.  ***********************************************************/
  57.  
  58. #define  DELAY_BETWEEN_MOVEMENTS   100 // in milliseconds
  59. #define  COL_AVERAGE_MOVE  4           // average column movement
  60. #define  ROW_AVERAGE_MOVE  4           // average row movement
  61. #define  COL_RANDOM_DELTA  2           // allowed change from average move to
  62. #define  ROW_RANDOM_DELTA  2           // randomize the bounces
  63.  
  64.  
  65. Forever(WindowHandle)   // while Bouncy window is valid, move the window around
  66. {
  67.    // Hide this resident window
  68.    HideWindow(Info().WinHandle);
  69.  
  70.    // // INCREASE PRIORITY OF THIS PROCESS
  71.    // #define ORD_DOS32SETPRIORITY     236
  72.    // #define PRTYC_TIMECRITICAL 3     // very high priority
  73.    // DynamicLink("doscalls",ORD_DOS32SETPRIORITY,BIT32,CDECL,
  74.    //             0/*all threads*/,PRTYC_TIMECRITICAL/*idletime*/,
  75.    //             0/*no process change at new level*/,0/*current process*/)
  76.  
  77.    // Get the dimensions of the desktop
  78.    #define HWND_DESKTOP 1
  79.    GetWindowPosition(HWND_DESKTOP,Col,Row,DeskWidth,DeskHeight);
  80.  
  81.    // Get initial position of the Bouncy Window
  82.    GetWindowPosition(WindowHandle,Col,Row,Width,Height);
  83.  
  84.    // determine maximum and minimum values for Col and Row
  85.    MinCol = 0;
  86.    MinRow = 0;
  87.    MaxCol = DeskWidth - Width;
  88.    MaxRow = DeskHeight - Height;
  89.  
  90.    // start random direction and delta
  91.    srand();
  92.    ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,rand() & 1);
  93.    RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,rand() & 1);
  94.  
  95.    // Finally, keep bouncing the window around at every interval
  96.    while ( WinIsWindow(WindowHandle) ) {
  97.  
  98.       // move window to new Row and Col position
  99.       MoveWindow(WindowHandle,Col += ColSpeed,Row += RowSpeed);
  100.  
  101.       // check if needs to bounce back to to hitting desktop edge
  102.       if ( ColSpeed < 0 ) {
  103.          if ( Col < MinCol )
  104.             ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,TRUE);
  105.       } else {
  106.          if ( MaxCol < Col )
  107.             ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,FALSE);
  108.       }
  109.       if ( RowSpeed < 0 ) {
  110.          if ( Row < MinRow )
  111.             RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,TRUE);
  112.       } else {
  113.          if ( MaxRow < Row )
  114.             RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,FALSE);
  115.       }
  116.  
  117.       suspend(DELAY_BETWEEN_MOVEMENTS);
  118.    }
  119. }
  120.  
  121. GetRandomSpeed(average,deviation,positive) // if not positive then negative
  122. {
  123.    // get a random deviation from average
  124.    deviate = (rand() % (2*deviation + 1)) - deviation;
  125.  
  126.    if ( positive )
  127.       return( average + deviate );
  128.    else
  129.       return( -average - deviate );
  130. }
  131.  
  132. WinIsWindow(hwnd) // return TRUE if this is still a valid window
  133. {
  134.    #define ORD_WIN32ISWINDOW  772
  135.    return PMDynamicLink("PMWIN",ORD_WIN32ISWINDOW,BIT32,CDECL,PMInfo().hab,hwnd)
  136. }
  137.  
  138. GetWindowPosition(hwnd,Col,Row,Width,Height)
  139. {
  140.    #define SWP_BLOB_SIZE 9 * 4
  141.    BLObSize(swp,SWP_BLOB_SIZE);
  142.    #define ORD_WIN32QUERYWINDOWPOS  837
  143.    if !DynamicLink("PMWIN",ORD_WIN32QUERYWINDOWPOS,BIT32,CDECL,hwnd,swp)
  144.       exit(1);
  145.    Height = BLObGet(swp,4,SWORD32);
  146.    Width = BLObGet(swp,8,SWORD32);
  147.    Row = BLObGet(swp,12,SWORD32);
  148.    Col = BLObGet(swp,16,SWORD32);
  149. }
  150.  
  151. MoveWindow(hwnd,col,row)
  152. {
  153.    #define ORD_WIN32SETWINDOWPOS 875
  154.    #define SWP_MOVE              0x0002
  155.    #define SWP_NOADJUST          0x0040
  156.    PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWPOS,BIT32,CDECL,
  157.                  hwnd,0,col,row,0,0,SWP_MOVE | SWP_NOADJUST);
  158. }
  159.  
  160. HideWindow(hwnd)
  161. {
  162.    #define ORD_WIN32SETWINDOWPOS 875
  163.    #define SWP_HIDE              0x0010
  164.    PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWPOS,BIT32,CDECL,
  165.                  hwnd,0,0,0,0,0,SWP_HIDE);
  166. }
  167.